Video compression and encoding method

ABSTRACT

Disclosed herein is a method for encoding at least one video frame having a plurality of blocks including a current block, including determining motion vectors for each of at least some of blocks surrounding the current block, identifying surrounding blocks having that have the same motion vector and assigning the identified surrounding blocks to a plurality of groups, determining a number of blocks in at least two of the plurality of groups and selecting a motion vector to encode the current block based on the determined number of blocks in the at least two groups.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. Utility patent applicationSer. No. 13/066,668, filed on Apr. 21, 2011, which is a continuation ofU.S. Utility patent application Ser. No. 11/170,629, filed on Jun. 28,2005, which in turn claims the benefit of U.S. Provisional PatentApplication No. 60/583,872, filed Jun. 28, 2004, all of which areincorporated herein by reference in their entirety.

COMPUTER PROGRAM LISTING APPENDIX

Two compact discs (in duplicate) have been submitted containing acomputer program listing; the contents of the compact discs areincorporated by reference herein in their entirety. The following filesare on the compact discs:

alloccommon.c

alloccommon.h

bitstream.c

block.h

blockd.h

boolhuff.c

boolhuff.h

cclib.h

colorcnv.cpp

colorcnv.h

common_types.h

config_dlg.cpp

config_onyx.cpp

context.c

CPUIdLib.h

dboolhuff.c

dboolhuff.h

dct.c

dct.h

debugmodes.c

decodemv.c

decodemv.h

decodframe.c

demode.c

demode.h

dequantize.c

dequantize.h

detokenize.c

detokenize.h

duck_dxl.h

duck_mem.h

dxl_plugin.h

dxvdecode.cpp

dxvdecode.hpp

encintra4×4.c

encintra4×4.h

encodeframe.c

encodeintra.c

encodeintra.h

encodemb.c

encodemb.h

encodemv.c

encodemv.h

entropy.c

entropy.h

entropymode.c

entropymode.h

entropymv.c

entropymv.h

extend.c

extend.h

filter.c

filter.h

filterc.c

filter_mmx.c

Filter_wmt.c

findnearmv.c

findnearmv.h

header.h

idct.c

idct.h

invtrans.c

invtrans.h

maskedmse_xmm.c

maskedsad_xmm.c

mcomp.c

mcomp.h

modecont.c

modecont.h

modecont2.c

modecontext.c

modecosts.c

modecosts.h

mse_xmm.c

mv.h

on2_mem.h

on2_mem_tracker.h

onyx.cpp

onyx.dsp

onyx.dsw

onyx.plg

onyx_lib.dsp

onyxc_lib.dsp

onyxconfig.txt

onyxd.dsp

onyxd_lib.dsp

onyxe_lib.dsp

onyxp_lib.dsp

onyxvfw.dsp

onyxvfw.plg

onyxvfwc.plg

onyxvfw.rc

onyx.h

onyxc_int.h

onyxd.cpp

onyxd.h

onyxdxv.c

onyxd_if.c

onyxd_int.h

onyxvfw.cpp

onyxvfw.h

onyxvfw2.cpp

onyx_if.c

onyx_int.h

onyx_settings.h

parms.cpp

pickintra.c

pickintra.h

postproc.c

postproc.h

psnr.c

psnr.h

quantize.c

quantize.h

rdopt.c

rdopt.h

recon.c

recon.h

reconinter.c

reconinter.h

reconintra.c

reconintra.h

reconintra4×4.c

reconintra4×4.h

regentry.cpp

regentry.h

resource.h

sad.c

sad.h

sad 16×16_wmt.c

sad16×16_xmm.c

sad4×4_xmm.c

setupintrarecon.c

setupintrarecon.h

StdAfx.cpp

StdAfx.h

textblit.c

tokenize.c

tokenize.h

vfwTemplate.h

vfw_config_dlg.cpp

vpvfw.def

vpvfw.rch

vvfwver.txt

vpvfwver.h

yuvconfig.c

yuvConfig.h

These files are exact ASCII versions of identically-titled non-ASCIIfiles submitted with the initial provisional application referencedabove.

COPYRIGHT NOTICE

A portion of the disclosure of this document contains material which issubject to copyright protection. The copyright owner has no objection tothe facsimile reproduction by anyone of this document or the disclosureas they appear in the USPTO files or records, but otherwise reserves allcopyright rights.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The invention relates to video compression and encoding methods, andmore specifically to video compression methods that employ techniques toincrease efficiency, compactability, and transmission of digital imageand video data.

2. Description of Related Art

Digital pictorial information, whether derived from an analogue sourceby a process of digitization or directly from a digital device, consistsof huge volumes of data. As the ability of devices to capture higherresolution images improves so too does the amount of data required fortheir digital representation. If stored in raw format a single image maywell require tens of mega-bytes of disk space.

The problem is further exacerbated when considering digital video data,especially for high definition video. A two-hour movie when stored inraw form at the highest resolution ATSC frame size (1920×1080 pixels at30 frames per second) requires almost 641 Gbyte of disk space. At a datarate of almost 89 Mbyte/s the bandwidth required for transmission goesway beyond what is currently available.

The encoding operation may be considered to be a three-stage process.First, a block predictor, created from data already available to thedecoder, is subtracted from the original data to form a prediction errorsignal. Second, the prediction error is block transformed and quantized.Finally, the transform coefficients are entropy coded to form a binarybitstream that constitutes the compressed frame.

The prediction stage may involve spatial or temporal prediction forvideo. For image compression, with no available temporal data, the onlyprediction mode available is spatial.

Many of the more successful algorithms have a two-dimensional blocktransform method at their core, partitioning each frame into rectangularblocks (usually 8×8 or 4×4) and applying the transform to each.Compression is achieved by coding the transform coefficients moreefficiently than the original spatial data can be coded.

The Discrete Cosine Transform (DCT) has received the most attention overthe last thirty years or so, being the transform of choice in all of theMPEG video compression and the original JPEG image compressionInternational Standards.

Another aspect of the invention covers the ability to reuse priortransmitted motion vectors, which may not appear directly adjacent tothe current block, and to use statistics on these prior transmittedmotion vectors to lessen the cost of encoding new motion vectors.

Motion fields tend to track real objects that move from one frame to thenext. These objects typically cover more than the typical block size.There is usually reasonable consistency of motion vectors from one blockto the next. Prior art makes use of this consistency by predicting a newmotion vector from the motion vectors of the surrounding blocks and thenencoding the difference between the real motion vector and the predictedmotion vector. The prior art also uses a smaller subset of blocks in theprediction, typically four surrounding motion vectors (left, above left,above, and above right).

In the prior art, digital image/video compression systems use varioustechniques of prediction to reduce data redundancy. In block-basedsystems, to efficiently encode a block of pixels, a prediction block isconstructed based on previously decoded data. That prediction block issubtracted from the source data and the residual signal is encoded usingtechniques such as transform coding. At the decoder the prediction blockmay be created from data that has already been decoded and theprediction error signal added back in to produce the reconstructedblock.

The terms intra- and inter-prediction indicate that the prediction blockis formed from data from the same image/video frame and previouslydecoded frame(s), respectively.

Sub Pixel motion estimation is used to build a prediction of a blockthat has moved from one frame to the next by something other than awhole pixel value. In sub-pixel motion estimation, the system attemptsto estimate what would have happened to the block if the real objectmoved by a non-integral amount.

The prior art used a fixed set of interpolating filters to predict ½, ¼,and even ⅛ pixel moves. The problem with this technique is two fold: thelonger the filter is the more likely you are to reproduce an imageartifact and two shorter filters perform a less accurate interpolationand thus tend to blur real image detail.

The prior art, including some standards based codecs such as H.264,describes the use of various types of filters for smoothing thediscontinuities that arise between blocks coded using discrete cosinetransforms (DCT) or other similar block based transforms.

The problem with conventional loop filters is that they typically eitherfail to adequately remove false block discontinuities or over smooth thereconstructed image and hence suppress real image detail.

This invention relates to an improved method for loop filtering thatincludes adaptive techniques that maximize the beneficial effects of thefilter and minimize the artifacts.

SUMMARY

This invention covers a novel approach to encoding motion vectors thatmakes use of motion vectors from surrounding blocks in a way thatdiffers from prior art.

The current invention is based on the premise that a better predictioncan be found by performing a motion search on multiple subdivisions ofthe same set of pixels. These subdivisions can be selected from adictionary of subdivisions or derived from a set of ‘subdividing’functions.

The current invention may be integrated into any image or videocompression algorithm that involves a block transform.

For purpose of the current invention the term image refers to arectangular array that contains either raw pixel values or predictionerror values.

Before the block transform is applied a process is carried out tosub-divide the image into a set of fixed partitions (for instance 16×16blocks of pixels). Then these fixed partitions are subdivided inmultiple ways using either a fixed set of subdivisions or a set offunctions that produce an arbitrary set of subdivisions. A motion searchis performed on each of the subdivisions and the best subdivision in arate distortion sense is selected. The best subdivision can either bedirectly encoded in the bitstream or it can be signaled throughtransmitted motion vectors on a more atomic subdivision level.

The benefit to an encoding in which the modes and motion vectors areencoded on an atomic level is that arbitrary patterns of motion vectorscan be encoded efficiently.

Generally, an aspect of the invention includes a method for determiningmotion vectors during video compression. Multiple subdivisions areperformed on an image or part of an image, and motion estimation isperformed on each of segment of every subdivision. It is determinedwhich of the subdivisions is the best using a metric, and a statisticsbased lossless coding technique is used to encode the motion vectorsgenerated by the compression process.

Preferably, the subdivisions are provided from a set of labelingfunctions, which subdivide the image using criteria that differs fromother labeling functions in the set.

Subdivision functions are preferably based on one or more of thefollowing functions:

a. Blocks with variances within a certain threshold are given the samelabel

b. Blocks with average pixel intensities within a given threshold aregiven the same label

c. Blocks with error scores within a certain threshold are given thesame label.

In addition or in the alternative, a specific dictionary of predefinedsubdivisions may be used.

The metric used to choose between the different subdivisions ispreferably a combination of at least one of the following: ratedistortion, sum squared prediction error, or sum absolute differenceerror score.

The invention also includes a method for encoding motion vectors. Animage or part of an image is broken up into a set of smaller partitions.For each partition, a mode is encoded which includes the following: leftmotion vector, above motion vector, zero motion vector, and/or newmotion vector. For each partition whose mode was new, motion vectorencode a motion vector into the bitstream.

This invention also presents a new set of methods for intra-predictionin image and video compression, which include the “TrueMotion”intra-prediction mode, the “Left Predictor” intra-prediction mode, the“Above Predictor” intra-prediction mode, context based intra-predictionmode encoding, cost biased intra-prediction mode selection, and frameadaptive intra-prediction mode entropy encoding.

The current invention also uses the known technique of motioncompensation to build a predictor for each inter coded block in theframe via sub-pixel motion. As mentioned above, prior art compressiontechniques use a fixed set of interpolating filters to predict ½, ¼, and½ pixel moves. The problem with this technique is two-fold: the longerthe filter is the more likely you are to reproduce an image artifact,and two shorter filters perform a less accurate interpolation and thustend to blur real image detail.

This invention solves these problems by performing adaptive pixelanalysis on the prediction filter and by picking between a set offilters that have different lengths. Shorter pixel filters are chosenwhen the results are less likely to be damaging. Longer filters arechosen when the clarity of the reconstructed frame is more important.

In another aspect of the invention, as mentioned above, the prior artpredicts a new motion vector from the motion vectors of the surroundingblocks and then encoding the difference between the real motion vectorand the predicted motion vector. The prior art also uses a smallersubset of blocks in the prediction. Typically four surrounding motionvectors: left, above left, above, and above right.

By contrast, the inventive method improves upon prior art by not justpredicting the motion vector, but also by using statistics generated inthe examination of the motion vectors of surrounding pixels ascontextual information for encoding the motion vectors.

Specifically, the invention includes a method for encoding motionvectors of images in block based video compression algorithms,comprising the steps of:

i) Subdividing each image into a set of fixed partitions;

ii) Further subdividing each partition into segments according to aplurality of alternative subdivisions, each segment comprising one ormore blocks of pixels;

iii) Selecting an optimal motion vector for each segment in eachalternative subdivision based on an error score for each segment;

iv) Calculating a combined error score for each alternative subdivisionequal to the sum of the error scores for each segment of thesubdivision;

v) Selecting the subdivision with the lowest combined error score andencoding the motion vectors that were selected for the selectedsubdivision in step iv) into the bitstream.

Preferably, the optimal motion vector selection step iii) of a currentpartition uses motion vectors selected from a previously encodedpartition. The combined error score calculating step iv) of a currentpartition preferably uses error scores calculated from a previouslyencoded partition. The subdivision selecting step v) of a currentpartition may use the subdivision selected from a previously encodedpartition. The plurality of alternative subdivisions may be a fixed setof subdivisions, or a set of subdivisions derived from labelingfunctions, or both a first set of fixed subdivisions and a second set ofsubdivisions that are derived from labeling functions. The set oflabeling functions includes at least one of the following: groupingblocks into segments according to variance; or grouping blocks intosegments according to average pixel intensity; or grouping blocks intosegments according to error score. Multiple subdivisions may be createdusing each labeling function of different thresholds.

The motion vector selecting step iii) may further include at least oneof the following steps: performing a motion search for each block orsegment and encoding the resulting new motion vectors; or using the samemotion vector as the block or segment to the left of the current blockor segment; or using the same motion vector as the block or segmentabove the current block or segment; or using a zero motion vector (0,0);or using a previously encoded motion vector from a block or segment thatis not immediately adjacent to the current block or segment.

The error score basis for selecting the motion vector in step iii) mayinclude a rate distortion calculation, or alternatively a predictionerror calculated either as the sum squared error or the sum of absolutedifferences.

In another aspect of the invention, a method for encoding motion vectorsin video compression is provided, including the steps of:

Subdividing each image into a set of fixed partitions, and for a givenpartition:

a) Examining the surrounding partitions' motion vectors in an orderbased on the proximity to the given partition;

b) Counting how many times each motion vector appears in the surroundingpartitions;

c) Using a subset of these counts for one or more of the following:

-   -   i) Determining which motion vector is re-used as a reference; or    -   ii) As context for losslessly encoding which motion vector is        re-used as a reference; or    -   iii) As context for losslessly encoding a new motion vector.

The counts from step b) may be distance weighted. Optionally, thismethod may further include:

Creating an N dimensional array as the lossless encoding context of c)ii) where N is the number of different motion vectors used inneighboring partitions; and

Using the count of each different motion vector to index each dimensionof the array,

Wherein the value stored in the array is a set of probabilities thatdetermine which motion vector to use as reference. Optionally, afunction on the counts from step b) may be used to determine a set ofprobabilities that determine the motion vector to use as a reference.

In another aspect of the invention, a method of encoding video and orimage data is provided having the steps of

-   -   a) Subdividing each image into a set of fixed partitions;    -   b) Giving each pixel in the partition a predicted value using        any one or more of the following equations:

X _(ij) =L _(i) +A _(j) −C;

X _(ij)=(Li ⁻¹+2L _(i) +L _(i+1)+2)/4;

X _(ij)=(Aj ⁻¹+2A _(j) +A _(j+1)+2)/4;

Where i and j represent the row and column position of X_(ij) within apartition, L_(i) is the pixel from the column left to the partition inthe same row of X_(ij), A_(j) is the pixel from the row above but in thesame column of X_(ij), C is the pixel on the intersection of the rowabove and the column left to the partition,

-   -   c) Subtracting the predicted values from the source pixel        values;    -   d) Quantizing and transforming the resultant value from step c)        using a transform function into transform coefficients; and    -   e) Losslessly encoding the transform coefficients of step d)        into the bitstream.

In another aspect of the invention, a method for intra prediction foruse in block based video compression/decompression algorithms isprovided having the following steps:

Subdividing each image into a set of fixed partitions;

Provisionally encoding each partition using a plurality of differentprediction modes in which pixels in the current partition are predictedby previously decoded pixels within the same image from the row aboveand the column to the left of the current partition, said provisionalencoding done by giving each pixel in the partition a predicted valueusing at least one of the following equations:

X _(ij) =L _(i) +A _(j) −C; or

X _(ij)=(Li ⁻¹+2L _(i) +L _(i+1)+2)/4; or

X _(ij)=(Aj ⁻¹+2A _(j) +A _(j+1)+2)/4;

Selecting the optimal mode using either a true rate distortion metric ora combination of a prediction error metric and a factor or functionrelating changes in bit cost or estimated bit cost for encoding thepartition to changes in prediction error;

Encoding the selected optimal mode and transmitting the selected optimalmode within the bitstream, and encoding the partition in accordance withthe selected optimal mode,

Wherein the selected optimal mode is encoded using a conditionalprobability distribution indexed or otherwise accessed according to theprediction modes of the previously encoded partitions above and to theleft of the current partition.

Optionally, the provisional encoding step entails using any two or moreof the specified equations. Optionally, the conditional probabilitydistribution is defined by a table of constants.

The probability distribution may be updated on a per frame basisaccording to statistics gathered relating to the frequencies orconditional frequencies of each mode in at least one prior frame. Theprobability distribution may be a fixed baseline distribution. Asanother alternative, the probability distribution is updated for animage only when the number of bits used to update the probabilitydistribution plus the number of bits required to encode all theprediction modes within the image using the updated probabilitydistribution is less than the number of bits required to encode all theprediction modes using either the baseline probability distribution orthe unchanged probability distribution from the previous frame.

The decision of intra prediction mode for a partition may be based on ametric that combines the cost of the modes with error scores of themodes, where the cost of an intra prediction mode of a partition iscalculated using Shannon cost of each mode calculated by the conditionalprobability distribution of the intra prediction modes for the partitionand the error score of the mode is calculated using the differencesbetween the predicted pixels values and the actual pixel values for thepartition.

Optionally, the following steps may be included: multiplying the cost ofeach mode with a constant; adding the multiplied cost of each mode tothe error score for the mode; and selecting the intra prediction modewith lowest combined score for the partition.

In another aspect of the invention, a method for inter prediction ofblocks of pixels using motion vectors in a video compression algorithmis provided, having the following steps:

Specifying the location of a block in a previously decoded referenceframe to be used as predictor, relative to the spatial position of theblock being predicted, by a two-dimensional motion vector;

Specifying the motion vector to ½ or ¼ pixel precision in the lumadomain and ¼ or ⅛ pixel precision in U and V;

Where a fractional pixel vector is used, deriving the predictor block byapplying a 6-tap 2 dimensional interpolation filter, whose coefficients,when implemented as a separable 2-dimensional filter such that theprediction block is first filtered in one dimension (horizontal orvertical) and the resulting filtered data block is then filtered in theother dimension, are as follows:

2 −11 108 36 −8 1 (¼ pixel) 3 −16 77 77 −16 3 (½ pixel) 1 −8 36 108 −112 (¾ pixel)

In another aspect of the invention, a method for inter prediction ofblocks of pixels using motion vectors in a video compression algorithmis provided, having the following steps:

Specifying the location of a block in a previously decoded referenceframe to be used as predictor, relative to the spatial position of theblock being predicted, by a two-dimensional motion vector;

Specifying the motion vector to ½ or ¼ pixel precision in the lumadomain and ¼ or ⅛ pixel precision in U and V;

Where a fractional pixel vector is used, deriving the predictor block byapplying of an interpolation filter selected from a plurality ofpossible filters according to the content of the data being filtered,

Wherein the plurality of interpolation filters includes a 6-tap 2dimensional interpolation filter, whose coefficients, when implementedas a separable 2-dimensional filter such that the prediction block isfirst filtered in one dimension (horizontal or vertical) and theresulting filtered data block is then filtered in the other dimension,are as follows:

2 −11 108 36 −8 1 (¼ pixel) 3 −16 77 77 −16 3 (½ pixel) 1 −8 36 108 −112 (¾ pixel)

In either of the immediately preceding embodiments, the filter isimplemented using floating point or fixed point arithmetic, or thefilter may not be implemented as a separable 2 dimensional filter. Oneof the filters that may optionally be selected may be a 2-tap bi-linearfilter, a 4-tap bi-cubic filter, or a 6-tap filter. The basis forselecting between the pluralities of possible filters may be themagnitude of the sum of inter-pixel differences. The basis for selectingbetween the interpolation filters may include the following steps:

Defining a first sum of differences between horizontally neighboringpixels in a block;

Defining a second sum of differences between vertically neighboringpixels in a block;

If the first sum of differences is less than a first threshold,selecting the bi-linear filter;

If the first sum of differences is greater than the first threshold butless than a second threshold, selecting the bi-cubic filter;

If the first sum of differences is greater than the second threshold butless than a third threshold, selecting the 6-tap filter;

If the second sum of differences is less than the first threshold,selecting the bi-linear filter;

If the second sum of differences is greater than the first threshold butless than the second threshold, selecting the bi-cubic filter;

If the second sum of differences is greater than the second thresholdbut less than the third threshold, selecting the 6-tap filter,

Wherein the first, second, and third thresholds may either be derived bythe encoder and the values coded in the bitstream, or have fixed valuesknown to both encoder and decoder.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a schematic of an example set of 16×16 block subdivisions.

FIG. 2 is a diagram showing the step-by-step generation of subdivisions.

FIG. 3 is a diagram showing the preferred bin weightings for block X.

FIG. 4 is a diagram showing calculations of tallies for block X.

FIG. 5 is a diagram showing the relative position of previously codedpixels C, A_(i), and L_(i) and the block being predicted X_(ij) in theimage/frame.

FIG. 6 is a diagram a number of blocks including block B_(rc) of animage/video frame.

FIG. 7 is a graph depicting the transfer function of bi-linear,bi-cubic, and the inventive 6-tap filters as gain as a function offrequency.

DETAILED DESCRIPTION

Description will now be given of the invention with reference to theattached FIGS. 1-7. It should be understood that these figures areexemplary in nature and in no way serve to limit the scope of theinvention, which is defined by the claims appearing herein below.

Motion Modes and Masked Motion Compression.

FIG. 1 is an example set of 16×16 block subdivisions. Each letter in theblocks represents a 4×4 set of pixels within a 16 by 16 block of pixels.

The invention is accomplished using the logic demonstrated with thefollowing pseudo-code.

TABLE 1 PSEUDO-CODE FOR SELECTING MOTION VECTORS Determine a set ofsubdivisions to test For each sub-division   For each labeled segmentwithin a subdivision Calculate the rate-distortion value (see Table II)for each of the following:   1)  Use the MV (motion vector) from segmentleft   1)  Use the MV from segment above   2)  Use no MV   Set segmentmv to the mv from above that gives you the lowest rate distortion valueIf that rate distortion value is above a preset threshold   Find thebest motion vector for the current labeled segment     Calculate therate distortion value for that segment     If that value < less thancurrent segment rate distortion     value       Set segment mv to bestmv   Add the current segment's rate distortion value to the current  subdivision's rate distortion value If the current subdivision's ratedistortion value is less than the best subdivision's rate distortionvalue yet seen   Record each of the subdivision's best segment MVs

TABLE II DETERMINING A SEGMENT'S RATE DISTORTION VALUE Segment RateDistortion Value = 0 For each block within a segment Rate =  # bits toencode mode (left, above, zero, or new MV)  + # bits to encode motionvector (only for new motion vector)  + # bits to encode residual errorsignal the block) Block Distortion = sum squared error for each pixelwithin the block Block Rate Distortion Value = Rate * Rate Factor +Distortion * Distortion Factor Segment Rate Distortion Value = SegmentRate Distortion Value   + Block Rate Distortion Value

TABLE III ENCODING THE MODES For each block within each partition   IfMV of the current block is the same as the mv of the left block   encode“left”   Else if MV of the current block is the same as the mv of theabove   block encode “above”   Else if the MV of the current block is(0,0) encode “zero”   Else encode “new motion vector”

This invention also covers the use of special labeling functions tocreate an arbitrary set of subdivisions. The goal in the design of thesefunctions is to produce segments of different size and shape; the hopeis that one of these segments will best match the moving objects on thescreen and thus produce a better prediction for the current block. Thecurrent embodiment of this invention specifies a set of possiblefunctions for use as follows:

-   -   1. Blocks with variances within a certain threshold are given        the same label    -   2. Blocks with average pixel intensities within a given        threshold are given the same label    -   3. Blocks with error scores within a certain threshold are given        the same label.

The invention also covers a method for generating different subdivisionsthat includes picking one of the above functions and applying itmultiple times with a different threshold for each desired subdivision.This method is illustrated in FIG. 2.

The thresholds can be selected dynamically to best insure that differentlabeling is set up.

Step 1—Calculate average pixel intensity

Step 2—Assign first block label A

Step 3—GO through the remaining blocks in raster order as follows:

If difference between current and left block is less than threshold &also less than or equal to the difference between the current and aboveblock

Assign the block the same label as the left block Else if differencebetween current block and the above block < threshold Assign the blockthe same label as the above block Else Assign the block the next labeledvalue

Step 4 Reapply with different thresholds (e.g., sample labelingthresholds of 2, 4, 9, and 15 are shown in FIG. 2).

Another aspect of the invention covers the ability to reuse priortransmitted motion vectors, which may not appear directly adjacent tothe current block, and to use statistics on these prior transmittedmotion vectors to lessen the cost of encoding new motion vectors.

Motion fields tend to track real objects that move from one frame to thenext. These objects typically cover more than the typical block size.There is reasonable consistency of motion vectors from one block to thenext. Prior art makes use of this consistency by predicting a new motionvector from the motion vectors of the surrounding blocks and thenencoding the difference between the real motion vector and the predictedmotion vector.

This invention covers a novel approach to encoding motion vectors thatmakes use of motion vectors from surrounding blocks in a way thatdiffers from prior art.

Surrounding blocks are tallied into 4 different bins:

-   -   Bin 1 is used to tally blocks with no motion vector    -   Bin 2 is used to tally blocks in which the nearest motion vector        appears    -   Bin 3 tallies blocks in which the next closest motion vector        appears    -   Bin 4 tallies blocks that can't fit into any of the other bins.

In the preferred embodiment the block tally is weighted by the block'scloseness to the block whose motion vector is being encoded (see FIG.3).

Set nearestMv to 0,0 Set nearMv to 0,0 For each block = 1 to 12   Ifmv[block]! = 0,0     nearestMv = mv[block]     Bin[2] +=binWeighting[block]     Break;   Else     Bin[1] += binWeighting[block]For each block = block to 12   If mv[block] == 0,0     Bin[1] +=binWeighting[block]   Else if mv[block] == nearestMV     Bin[2] +=binWeighting[block]   Else     NearMV = mv[block]     Bin[3] +=binWeighting[block]     Break For each block = block to 12   Ifmv[block] == 0,0     Bin[1] += binWeighting[block]   Else if mv[block]== nearestMV     Bin[2] += binWeighting[block]   Else if mv[block] ==nearMV     Bin[3] += binWeighting[block]   Else     Bin[4] +=binWeighting[block]

These counts in each bin are used in a number of different ways:

1) A mode is encoded which can be one of the following:

-   -   a. No motion vector    -   b. Nearest motion vector    -   c. Next Nearest Motion Vector    -   d. New Motion Vector    -   e. Subdivided Motion Vector

The mode refers to what motion vector is used for the block.

2) The context used to encode this mode is the counts associated withthe 4 bins.

Using Bin Counts to Entropy Encode Modes Table IV

3) The motion vector associated with the bin with the highest count isused as a prediction for a new motion vector if the mode is new motionvector. (If the bin is bin 4 then the predicted motion vector is 0,0).

TABLE IV USING BIN COUNTS TO ENRTOPY ENCODE MODES A. CalculateProbability of Nearest MV mode Given Bin 1 is the size it is (see FIG.4) B. If Mode is Nearest MV C. Shannon Encode a 1 with probability givenfrom step A D. Else E. Shannon Encode a 0 with probability given fromstep A F. Calculate Probability of Zero MV mode Given Bin 0 is the sizeit is (see FIG. 4) G. If Mode is Zero MV 2 H. Shannon Encode a 1 withprobability given from step F I. Else J. Shannon Encode a 0 withprobability given from step F K. Calculate Probability of Near MV modeGiven what Bin 2 is (see FIG. 4) L. If Mode is near MV M. Shannon Encodea 1 with probability given from step K N. Else O. Shannon Encode a 0with probability given from step K P. Calculate Probability of New MVmode Given what Bin 3 is (see FIG. 4) Q. If Mode is new MV R. ShannonEncode a 1 with probability given from step P S. Else T. Shannon Encodea 0 with probability given from step P The probabilities can either begiven by a straight function an example follows:   Probability =BinCount[1]/30.0   Or the value to use can be calculated via a lookuptable   Probability = P[BinCount[1]]       Intra-Prediction

The current invention defines a set of block predictors that use datafrom one or more previously decoded blocks to produce the closestapproximation to data in the block that is being predicted.

In the preferred embodiment various block sizes are used, but theinvention may be applied to blocks of arbitrary size which may include,but is not limited to, the set 16×16, 8×16, 16×8, 8×8, 8×4, 4×8 and 4×4.For the purposes of description of the various prediction modes weconsider the case where the block size is 4×4. The methods presented mayeasily be extended to arbitrary block sizes without loss of generality.

FIG. 5 shows the relative position of the pixels in previously decodedblocks and those of the block that have to be predicted. In the sectionsthat follow reference should be made to this figure.

C A₀ A₁ A₂ A₃ A₄ L₀ X₀₀ X₀₁ X₀₂ X₀₃ L₁ X₁₀ X₁₁ X₁₂ X₁₃ L₂ X₂₀ X₂₁ X₂₂X₂₃ L₃ X₃₀ X₃₁ X₃₂ X₃₃

FIG. 5 Relative positions of the previously decoded pixels C, Ai andL_(i) and the block being predicted X_(ij) in the image/frame.

The values L_(i) refer to pixels in the block to the left of the currentblock, which is referred to as the “Left” block. Similarly, the valuesA_(i) and C refer to pixels in the blocks above the current block, whichis referred to as the “Above” block.

“TrueMotion” Intra-Prediction Mode

One prediction mode used in the current invention is defined by thefollowing equation to calculate X_(ij):

X _(ij) =L _(i) +A _(j) −C;

“Above Predictor” Intra-Prediction Mode

A further prediction mode, called the “Above Predictor”, in the currentinvention is defined by the following equation to calculate Xij:

X _(ij)=(Li ⁻¹+2L _(i) +L _(i+1)+2)/4

It is essentially a weighted predictor based on previously decoded pixelvalues from the blocks directly above the block being predicted. Asthese values come from previously decoded blocks these values will beavailable at the decoder when required.

“Left Predictor” Intra-Prediction Mode

A further prediction mode, called the “Left Predictor”, in the currentinvention is defined by the following equation:

X _(ij)=(Aj ⁻¹+2A _(j) +A _(j+1)+2)/4

It is essentially a weighted predictor based on previously decoded pixelvalues from the block to the left of the block being predicted. As thesevalues come from previously decoded blocks these values will beavailable at the decoder when required.

Context Based Intra-Prediction Mode Encoding

The current invention embodies a new context based encoding scheme forencoding intra-prediction mode decisions. This encoding method is usedto encode an intra-prediction mode for a block in cases where both theleft and above block are also coded using an intra-prediction mode.

As shown in FIG. 6, block Brc is located in the r^(th) block row and thec^(th) block column of the current image/video frame.

From experiments, the intra-prediction mode of block B_(rc), Mode_(rc),is found to be closely correlated to the intra-prediction modes ofblocks and B_(rc(1)−) when intra-prediction is used for both B_((r−1)c)and B_(r(c−1)).

In the current invention both the encoder and decoder maintain aconditional probability distribution of intra-prediction modes for aparticular frame. The conditional probability model, or context,consists of the intra-prediction modes used to code the blocksimmediately to the left of and above the current block:

Prob(MCURRENT|M _(LEFT) =m _(LEFT) ,M _(ABOVE) =m _(ABOVE))

Where M_(CURRENT) represents the intra-prediction mode of the currentblock, M_(ABOVE) and M_(LEFT) represent the modes of the two neighboringblocks and m_(ABOVE) and m_(LEFT) represent the actual mode used in theneighboring blocks.

In other words, for every possible combination of intra-prediction modesthat the above and left blocks may use, a probability distribution iscreated for the set of possible values for the current block mode.

For a particular intra-predicted block the selected mode is then encodedinto the bitstream as follows:

-   -   Find the intra-prediction mode for the current block,        Mode_(CURRENT)    -   Determine the intra-prediction mode used by the left block,        Mode_(LEFT)    -   Determine the intra-prediction mode used by the above block,        Mode_(ABOVE)    -   Look-up the conditional probability for Mode_(CURRENT) for the        context (Mode_(LEFT), Mode_(ABOVE)),        P(Mode_(CURRENT)|Mode_(LEFT), Mode_(ABOVE))    -   Use this probability to encode the mode decision using, for        example, an arithmetic or Huffman coder.    -   In the preferred embodiment the above conditional probability        distributions are used to encode each intra-prediction mode        using an arithmetic encoder.

Cost Biased Intra-Prediction Mode Selection

The selection of a prediction mode to use for a particular block iscommonly based solely on minimizing the prediction error as measured bysome defined error metric. Many such metrics have been used in the priorart examples being the sum of absolute differences, the sum of squareddifferences, and the variance.

The major problem with this method of selecting mode is that it does notconsider the cost of encoding the prediction mode decision itself in tothe bitstream, resulting in a possibly non-optimal solution. Forexample, if the mode that produces the smallest prediction errorrequires significantly more bits to encode in the bitstream than analternative mode that has only a slightly larger prediction error, itmay be better to use the alternative prediction mode to achieve a moreoptimal cost-compression trade-off.

To overcome this problem, the current invention embodies a cost biasedstrategy in selecting best overall intra-prediction mode for eachintra-predicted block. The basic idea is to consider the overallencoding cost of each prediction mode, including both the signaling costof the mode choice and the cost of coding the prediction error signal,and select the intra-prediction mode with best overall efficiency.

The current invention converts the cost of each prediction mode into aquantity that is added into the prediction error resulting from codingusing that mode. The mode with the smallest aggregate error score isthen selected. The decision process for each block involves thefollowing steps:

-   -   a. Find the intra-prediction mode of the block above and the        block to the left, m_(ABOVE) and m_(LEFT),    -   b. Find the probability distribution        P(Mode_(CURRENT)|Mode_(LEFT), Mode_(ABOVE)),    -   c. Use Shannon theory to convert the probability distribution to        number of bits necessary to encode each prediction mode:        Bits_(m),    -   d. Calculate the error metric sum of squared differences for        each prediction mode: SSD_(m),        -   Calculate SSD(m)+Bits(m)*C, where C is an empirical value            that measures the amount of SSD per bit when the difference            signal is encoded using transform coding. C is dependent            upon the quantizer level and is commonly referred to as a            rate distortion metric.    -   e. The Intra-prediction mode resulting in the smallest value in        step (e) is then chosen.

6. Frame Adaptive Intra-Prediction Entropy Encoding

The content of video changes from frame to frame, which means theprobability distribution described in sections 4 and 5 could changeaccordingly. The actual probability distribution of each video frameprovides the best coding efficiency for that frame.

However, any updating of such a distribution involves an overhead costof transmitting the updates in the compressed bitstream. The currentinvention presents a method to determine when an update is appropriate.

The process proceeds as follows:

-   -   a) Remember the conditional mode probability distribution for        the previous frame, or known baseline if no previous frame        exists, P_(PREVIOUS),    -   b) Count the number of times each mode is selected in the        current frame to produce the conditional mode probability        distribution for the current frame, P_(CURRENT),    -   c) Encode all modes using the previous frame probability        distribution, resulting in B_(PREVIOUS) bits,    -   d) Encode all modes using the current frame probability        distribution, resulting in B_(CURRENT) bits,    -   e) Calculate the number of bits required to update the        probability distribution from that used for the previous frame        and that computed from the current frame, B_(UPDATE)    -   f) If (B_(CURRENT)+B_(UPDATE))<B_(PREVIOUS) then it is cost        effective to transmit the update and use it to encode modes in        the current frame. Otherwise, use the existing mode probability        distribution.

Sub-Pixel Filtering

A two-dimensional motion vector specifies the location, relative to thespatial position of the block being predicted, of the block in apreviously decoded reference frame to be used as predictor. A decodedprediction error signal is subsequently added to the prediction block tocreate the final reconstructed block.

Motion vector components are specified to ¼ sample accuracy for lumablocks, the vector for the corresponding chroma blocks is derived fromthis. In the preferred embodiment the YUV 4:2:0 color space is used asthe internal coding format. In this format the distance between twochroma samples is twice that of the distance between luma samples.Consequently, if the luma components of a motion vector are specified to¼ sample accuracy, then the chroma components are at ⅛^(th) samplevalues.

To handle all cases a separate filter is specified for each of the eight⅛^(th) sample positions, i.e. at positions {0, ⅛, ¼, ⅜, ½, ⅝, ¾, ⅞}between pixels. The first of these positions is, trivially, the positionof the pixel value itself and requires no interpolation.

In order to generate the values at fractional locations between pixels,some form of interpolation process is applied. The preferred embodimentspecifies an interpolation algorithm that employs a set of separabletwo-dimensional filters.

For each inter-coded luma block that has a non-zero motion vector, datafrom the reference frame at a location relative to the current block asspecified by the non-fractional part of the motion vector is firstfiltered horizontally to produce the fractional horizontal positiondata. The resulting data is then filtered vertically to produce therequired result. Applying the vertical filter before the horizontal isequally valid, but may produce different results. In each case theparticular filter used is determined by the fractional part of themotion vector component. For example, if the motion vector were (4½, ¾)then the horizontal and vertical filters corresponding to the ½ and ¾positions would be used, respectively.

Negative motion vector components require slightly different selection.For example, the component −3¾ actually lays ⅛ of the way between thetwo pixel positions and so requires selection of the ¼ position filter.

In the preferred embodiment three families of filter are used asfollows:

-   -   Two-tap bi-linear filter (see Table V),    -   Four tap bi-cubic filter (alpha=−0.5) (see Table VI)    -   6-tap filter (see Table VII)

TABLE 5 Coefficients of the 2-tap Bi-linear Filter (Normalized to 128)Tap Position t₀ t₁ 0 128 0 ⅛ 112 16 ¼ 96 32 ⅜ 80 48 ½ 64 64 ⅝ 48 80 ¾ 3296 ⅞ 16 112

TABLE 6 Coefficients of the 4-tap bi-cubic Filter alpha = −0.5(Normalized to 128) Tap Position t⁻¹ t₀ t₁ t₂ 0 0 128 0 0 ⅛ −6 123 12 −1¼ −9 111 29 −3 ⅜ −9 93 50 −6 ½ −8 72 72 −8 ⅝ −6 50 93 −9 ¾ −3 29 111 −9⅞ −1 12 123 −6

TABLE 7 Coefficients of the 6-tap Filter (Normalized to 128) TapPosition t⁻² t⁻¹ t₀ t₁ t₂ t₃ 0 0 0 128 0 0 0 ⅛ 0 −6 123 12 −1 0 ¼ 2 −11108 36 −8 1 ⅜ 0 −9 93 50 −6 0 ½ 3 −16 77 77 −16 3 ⅝ 0 −6 50 93 −9 0 ¾ 1−8 36 108 −11 2 ⅞ 0 −1 12 123 −6 0

In the tables, each row specifies a set of filter taps for thegeneration of the specified ⅛th pixel position. The taps are applied toa contiguous set of pixels in the appropriate direction, horizontal orvertical, such that the taps t₀ and t₁ are applied to the pixels closestto the fractional position being interpolated. All of the filters arenormalized to 128 to permit integer only implementation. After theapplication of the filter the values are re-normalized and clipped backto the range 0 to 255.

The bi-linear filter is the simplest to implement but can producesresult that appear blurred due to its narrow pass-band. This filter isused in areas of low variation to suppress noise and reduce any codingartifact that may be present.

The alpha=−0.5 bi-cubic filter is a reasonable compromise 4-tap filter.It produces sharper results than the bilinear filter without introducingringing artifacts since it has sub-unit gain throughout the entirefrequency spectrum.

The first two filters both exist as prior art and have been extensivelyused. The six-tap filter, however, forms part of the current invention.The filter taps were derived to produce the widest possible pass-band inthe transfer function, whilst containing virtually no above unit gainthroughout the frequency spectrum.

FIG. 7 plots the transfer functions for all three-filter families at the½ pixel position.

FIG. 7 Transfer Function of Bi-Linear, Bi-Cubic and On2 6-Tap Filters.

The selection of which filter family to use for a particular block isbased on the content of the data being filtered. In a preferredembodiment, the magnitude of the sum of inter-pixel differences in thedirection that the filter is to be applied is used to select betweenfilter types as follows:

HDiff = Sum of differences between horizontally neighboring pixels inblock; VDiff = Sum of differences between vertically neighboring pixelsin block; If (HDiff < T₀)   HFilter = Bi-Linear Filter; Else if (HDiff <T₁)   HFilter = Bi-Cubic Filter; Else if (HDiff < T₂)   HFilter = 6-tapFilter; If (VDiff < T₀)   VFilter = Bi-Linear Filter; Else if (VDiff <T₁)   VFilter = Bi-Cubic Filter; Else if (VDiff < T₂)   VFilter = 6-tapFilter;

Where the thresholds T₀, T₁, and T₂ may either be derived by the encoderand the values coded in the bitstream, or have fixed values known toboth encoder and decoder.

Output from the filter is positioned at its center in the sense that,for a length N filter (where N is even), the first N/2 filter taps aremultiplied by the N/2 pixels directly to the left of (or above) theposition being interpolated, and the final N/2 taps multiplied by theN/2 pixels directly to the right of (or below) the position beinginterpolated. The final output value is the sum of these N products,appropriately rounded and normalized.

It should be noted that pixels outside of the block are used during thefiltering process since the filter extends beyond the bounds of theblock boundary at either end. To this end the reference frame must bepadded beyond its boundary by repeating the value of the edge pixel asrequired.

The filtering process is summarized by the following pseudo-code. Thepseudo-code makes the assumption that the filter is 6-tap. Smallerfilters must be padded with zeros and have the coefficients centered,e.g. the two-tap and four-tap filters are specified as {0, 0, t0, t1, 0,0} and {0, t−1, t0, t1, t2, 0}, respectively:

#define FILTER_WEIGHT 128  // Sum of the filter taps #defineFILTER_SHIFT 7 // Number of bits to shift output from // filter by toeffect normalization void FilterBlock2d (   unsigned char *SrcPtr, //Pointer to prediction block data in reference frame   unsigned char*OutputPtr, // Pointer to output block being interpolated  intSrcPixelsPerLine, // Number of pixels in input & output line  short*HFilter, // Pointer to array containing 6-tap Horizontal Filter  short*VFilter // Pointer to array containing 6-tap Vertical Filter ) {   intFData[9*4]; // Temp data bufffer used in filtering  // Note: SrcPtrpoints to the block of pixels in the prediction frame  // that thenon-fractional part of the motion vector indicates.   // Step 1: Filterblock horizontally using specified filter:   FilterBlockHorizontally (SrcPtr−(2*SrcPixelsPerLine),                  SrcPixelsPerLine, FData,9, 4, HFilter );   // Step 2: Filter block vertically using specifiedfilter:   FilterBlockVertically ( FData+8, 4, OutputPtr, 4, 4, VFilter); } void FilterBlockHorizontally (  unsigned char *SrcPtr,  intSrcPixelsPerLine,  int *OutputPtr,  int OutputHeight,  int OutputWidth, int *Filter ) {  int i, j;  int Temp;  for ( i=0; i<OutputHeight; i++ ) {     for ( j=0; j<OutputWidth; j++ )     {       // Apply filter:      Temp =   ((int)SrcPtr[−2] * Filter[0]) +          ((int)SrcPtr[−1] * Filter[1]) +           ((int)SrcPtr[ 0] *Filter[2]) +           ((int)SrcPtr[ 1] * Filter[3]) +          ((int)SrcPtr[ 2] * Filter[4]) +           ((int)SrcPtr[ 3] *Filter[5]);       // Add in the rounding value based on filter-tap sum:      Temp += (FILTER_WEIGHT >> 1);       // Normalize output to range0-255:       Temp = Temp >> FILTER_SHIFT;       if ( Temp < 0 )        Temp = 0;       else if ( Temp > 255 )         Temp = 255;      // Store output value:       OutputPtr[j] = Temp;       SrcPtr++;    }     // Move to start of next row:     SrcPtr   += SrcPixelsPerLine− OutputWidth;     OutputPtr += OutputWidth;   } } voidFilterBlockVertically (  int *SrcPtr,  int SrcPixelsPerLine,  unsignedchar *OutputPtr,  int OutputHeight,  int OutputWidth,  int *Filter ) { int i, j;  int Temp;  for ( i=0; i<OutputHeight; i++ )  {     for (j=0; j<OutputWidth; j++ )     {       // Apply filter:       Temp=  ((int)SrcPtr[−2*SrcPixelsPerLine] * Filter[0]) +          ((int)SrcPtr[−1*SrcPixelsPerLine] * Filter[1]) +          ((int)SrcPtr[ 0*SrcPixelsPerLine] * Filter[2]) +          ((int)SrcPtr[ 1*SrcPixelsPerLine] * Filter[3]) +          ((int)SrcPtr[ 2*SrcPixelsPerLine] * Filter[4]) +          ((int)SrcPtr[ 3*SrcPixelsPerLine] * Filter[5]);       // Addin the rounding value based on filter-tap sum:      Temp +=(FILTER_WEIGHT >> 1);       // Normalize output to range 0-255:      Temp = Temp >> FILTER_SHIFT;       if ( Temp < 0 )         Temp =0;       else if ( Temp > 255 )         Temp = 255;       // Storeoutput value:       OutputPtr[j] = (unsigned char)Temp;       SrcPtr++;    }   // Move to start of next row:   SrcPtr +=  SrcPixelsPerLine −OutputWidth;   OutputPtr +=  OutputWidth;  } }

Having described the invention, it is to be understood that theinvention is defined not by the above description but by the claimsappearing herein below. Various modifications that may be made by one ofordinary skill in the art are considered to be within the scope of theinvention.

1. A method for encoding at least one video frame having a plurality ofblocks including a current block, comprising: determining motion vectorsfor each of at least some of blocks surrounding the current block;identifying surrounding blocks having that have the same motion vectorand assigning the identified surrounding blocks to a plurality ofgroups; determining a number of blocks in at least two of the pluralityof groups; and selecting a motion vector to encode the current blockbased on the determined number of blocks in the at least two groups.